#include "Shooter_PCH.h"
#include "VertexArray.h"

/*--------------------------------------------------------------------------*/

VertexArray::VertexArray()
{
	glGenVertexArrays(1, &arrayHandle);
	std::cout << "Created VAO. Handle = " << arrayHandle << std::endl;
}

/*--------------------------------------------------------------------------*/

VertexArray::~VertexArray()
{
	glDeleteVertexArrays(1, &arrayHandle);
	std::cout << "Deleted VAO. Handle = " << arrayHandle << std::endl;
}

/*--------------------------------------------------------------------------*/

void VertexArray::Bind()
{
	glBindVertexArray(arrayHandle);
}

/*--------------------------------------------------------------------------*/

void VertexArray::Unbind()
{
	glBindVertexArray(0);
}

/*--------------------------------------------------------------------------*/

void VertexArray::AttachVertexBuffer( VertexBuffer* buffer )
{
	glBindVertexArray(arrayHandle);
	
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glEnableVertexAttribArray(2);

	glVertexAttribPointer(0,	3,	GL_FLOAT,	GL_FALSE,	sizeof(Vertex),		(void*) offsetof(Vertex, position));
	glVertexAttribPointer(1,	3,	GL_FLOAT,	GL_FALSE,	sizeof(Vertex),		(void*) offsetof(Vertex, normal));
	glVertexAttribPointer(2,	2,	GL_FLOAT,	GL_FALSE,	sizeof(Vertex),		(void*) offsetof(Vertex, texcoord));
}

/*--------------------------------------------------------------------------*/
